package utils

import (
	"fmt"
	"gorm.io/driver/mysql"

	"gorm.io/gorm"
	"lgb24kcs.com/im/config"
)

func NewMysql() *gorm.DB {
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		global.App.Viper.GetString("mysql.DbUser"),
		global.App.Viper.GetString("mysql.DbPwd"),
		global.App.Viper.GetString("mysql.DbHost"),
		global.App.Viper.GetInt("mysql.DbPort"),
		global.App.Viper.GetString("mysql.DbName"))
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	db.AutoMigrate()
	return db

}
